package implementor;

import org.opencv.core.Mat;
import org.opencv.imgproc.Imgproc;

public class CannyEdgeFilter implements Filter {
    private final double threshold1;
    private final double threshold2;
    
    public CannyEdgeFilter() {
        this(50, 150);
    }
    
    public CannyEdgeFilter(double threshold1, double threshold2) {
        this.threshold1 = threshold1;
        this.threshold2 = threshold2;
    }
    
    @Override
    public Mat apply(Mat image) {
        Mat grayImage = new Mat();
        Mat edges = new Mat();
        Mat result = new Mat();

        // 转换为灰度图
        Imgproc.cvtColor(image, grayImage, Imgproc.COLOR_BGR2GRAY);

        // 应用Canny边缘检测
        Imgproc.Canny(grayImage, edges, threshold1, threshold2);

        // 转回彩色图像
        Imgproc.cvtColor(edges, result, Imgproc.COLOR_GRAY2BGR);
        
        return result;
    }
    
    @Override
    public String getName() {
        return "CannyEdge";
    }
}